js代码
onReachBottom: function () {
//console.log('页面上拉触底事件的处理函数');
let pthis = this;
let page = this.data.page;
let newpage = page + 1;
app.util.request({
url: 'entry/wxapp/Fotoplace',
data: {
m: 'zhou_youx',
uid: app.globalData.uid,
page: newpage,
},
method: 'post',
success: function (response) {
if (response.data.code == 120000) {
wx.showToast({
title: '已经加载完数据了',
icon: 'none',
duration: 2000
})
return;
}
let jdata = pthis.data.list;
//console.log(jdata);
let ndata = response.data.data.rated;
//console.log(ndata);
jdata = jdata.concat(ndata)
//console.log(jdata);
pthis.setData({
'list': jdata,
'page': newpage
});
}
});
},
json配置
{
"usingComponents": {},
"onReachBottomDistance":50
}
PHP代码
$pindex = max(1, intval($_GPC['page']));
$psize = 10;
$condition = 'uniacid = :uniacid and openid=:openid';
$params = array(':uniacid' => $_W['uniacid'], ':openid' => $openid);
$sql = 'SELECT * FROM ' . tablename('zhou_youx_integral_jilu') . ' where ' . $condition . ' ORDER BY id DESC LIMIT ' . (($pindex - 1) * $psize) . ',' . $psize;
$list = pdo_fetchall($sql, $params);
if (empty($list)) {
$data['rated'] = '';
$data['code'] = '120000';
$data['msg'] = '成功';
$data['data'] ='';
return json_encode($data);
}else{
foreach ($list as $k=>&$v){
$v['createtime'] = date("Y-m-d H:i",$v['createtime']);
}
$res['code'] = 120001;
$res['msg'] = '成功';
$res['data'] = $list;
return json_encode($res);
}